$(document).ready(function() {
	set_footer_position();

	img_button_bind(".cancel_button", "imgs/publish/cancel_button_normal.png", "imgs/publish/cancel_button_hover.png", "imgs/publish/cancel_button_active.png");
	img_button_bind(".publish_button", "imgs/publish/publish_button_normal.png", "imgs/publish/publish_button_hover.png", "imgs/publish/publish_button_active.png");

	$(".select_item").click(function() {
		$(".current_select").removeClass("current_select");
		$(this).addClass("current_select");
	});

	form_bind();

	$(".cancel_button").click(function() {
		window.location.href = "blog_home.html";
	});

	select_item_bind();

	file_button_bind();
});

/**
* 选择发布的内容类型按钮的事件绑定（处理切换面板）
*/
function select_item_bind() {
	$("#text_item").click(function() {
		$(".current_content").css('visibility', 'hidden');
		$(".current_content").removeClass("current_content");
		$("#publish_text_content").addClass("current_content");
		$("#publish_text_content").css('visibility', 'visible');
	});

	$("#photo_item").click(function() {
		$(".current_content").css('visibility', 'hidden');
		$(".current_content").removeClass("current_content");
		$("#publish_photo_content").addClass("current_content");
		$("#publish_photo_content").css('visibility', 'visible');
	});

	$("#music_item").click(function() {
		$(".current_content").css('visibility', 'hidden');
		$(".current_content").removeClass("current_content");
		$("#publish_music_content").addClass("current_content");
		$("#publish_music_content").css('visibility', 'visible');
	});

	$("#link_item").click(function() {
		$(".current_content").css('visibility', 'hidden');
		$(".current_content").removeClass("current_content");
		$("#publish_link_content").addClass("current_content");
		$("#publish_link_content").css('visibility', 'visible');
	});
}

/**
* 文件选择按钮的事件绑定
*/
function file_button_bind() {
	$("#photo_file").hover(function() {
		$("#photo_file_button").attr('src', 'imgs/publish/publish_photo_button_hover.png');
	}, function() {
		$("#photo_file_button").attr('src', 'imgs/publish/publish_photo_button_normal.png');
	}).mousedown(function() {
		$("#photo_file_button").attr('src', 'imgs/publish/publish_photo_button_active.png');
	}).mouseup(function() {
		$("#photo_file_button").attr('src', 'imgs/publish/publish_photo_button_normal.png');
	});

	$("#music_file").hover(function() {
		$("#music_file_button").attr('src', 'imgs/publish/publish_music_button_hover.png');
	}, function() {
		$("#music_file_button").attr('src', 'imgs/publish/publish_music_button_normal.png');
	}).mousedown(function() {
		$("#music_file_button").attr('src', 'imgs/publish/publish_music_button_active.png');
	}).mouseup(function() {
		$("#music_file_button").attr('src', 'imgs/publish/publish_music_button_normal.png');
	});
}

/**
* 文本编辑器的创建
*/
function form_bind() {
	var editor;
	KindEditor.ready(function(K) {
		editor = K.create('textarea[name="content"]', {
			resizeType : 1,
			allowPreviewEmoticons : false,
			allowImageUpload : false,
			items : [
				'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
				'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
				'insertunorderedlist', '|', 'emoticons', 'image', 'link']
		});
	});
}